apiready = function(){
seajs.use(['../../V',"../../api","../../jquery","../../app","../../service"],function(V,$api,$,$app,service){
	var vm = {
		el: '#shop',
	  	data: {
				unionId: '',
				logo: ''
	  	},
	  	mounted:function() {
				api.addEventListener({
				    name: 'closeOpenShop'
				}, function(ret, err){
				    if(ret){
						api.closeWin();
				    }
				});
	  	},
	  	methods:{
				// 上传图片
				setLogo: function () {
					var that = this;
					$app.getPictureS(2,1,service['fileupload'],function(res){
						that.logo = res[0];
						console.log('===================')
						console.log(JSON.stringify(res))
					});
				},

				// 提交店铺信息
				shopNameSumit: function () {
					var that = this;
					var appId = $app.appid;
					var shopName = this.$refs.shopName.value;
					var unionid = $api.getStorage("shop_unionid");
					var userid = $api.getStorage("user").data.out_user_id;

					if (shopName == '' || shopName == null) {
						api.toast({
						    msg: '请输入店名!',
						    duration: 2000,
						    location: 'middle'
						});
						return;
					}
					if (shopName.length>15) {
						api.toast({
						    msg: '店名不能超过15个字',
						    duration: 2000,
						    location: 'middle'
						});
						return;
					}
					if (that.logo == '' || that.logo == null) {
						api.toast({
						    msg: '请选择店铺封面',
						    duration: 2000,
						    location: 'bottom'
						});
						return;
					}

					$app.ajax(
						service.openShop,
						{
							data: {
								values: {
									appid: appId,
									userid: userid,
									shop_name: shopName,
									shop_logo: that.logo
								}
							}
						},
						function (res) {
							if (res.message == '成功') {
								$app.ajax(
									service.shopDetail,
									{
										data: {
											values: {
												appid: appId,
												userid: userid,
											}
										}
									},
									function (ret) {
										console.log('要根据店铺是否有地址信息跳转页面（没有店铺地址就跳转到编辑店铺页面让他填写店铺地址，有的话就直接跳到店铺中心）')
										console.log(JSON.stringify(ret))
										if(ret.data.shop_location == ""){
											api.openWin({
													name: 'shopCard',
													pageParam: {
														shopId: ret.data.shop_code,
														page_from: 'open_shop'
													},
													url: '../shop_card/shop_card.html',
													reload: true
											});
										}else{
											api.openWin({
													name: 'my_shop',
													url: '../my_shop/my_shop.html',
													reload: true
											});
										}

									})

								// api.closeWin();
							}
						}
					);
				}
	  	}
	};
	var even = function(){
		api.setStatusBarStyle({
	  		style: 'dark',
	  		color: 'transparent'
	  	});
	};
	var newVue = new Vue(vm);
	even();
});
}
